package com.ycy.smartcourseselection.controller;

import com.ycy.smartcourseselection.common.PageResVO;
import com.ycy.smartcourseselection.common.ResData;
import com.ycy.smartcourseselection.dto.course.*;
import com.ycy.smartcourseselection.dto.student.FindAllStuDTO;
import com.ycy.smartcourseselection.service.CourseService;
import com.ycy.smartcourseselection.vo.course.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

@Api(tags = "课程管理")
@RestController
@RequestMapping("/course")
public class CourseController {
    @Resource
    private CourseService courseService;

    //回复课程
    @GetMapping("/recover")
    @ApiOperation(value="课程 -- 课程恢复")
    public ResData<Boolean> recoverCourse(String courseId) {
        return courseService.recoverCourse(courseId);
    }

    //分页查课程信息
    @PostMapping("/findPage")
    @ApiOperation(value="课程 -- 分页查",notes = "otherParams中的条件可选,支持联查")
    public ResData<PageResVO<CourseVO>> findPageCourses(@RequestBody FindPageCourseDTO findPageCourseDTO) {
        return courseService.findPageCourses(findPageCourseDTO);
    }
    //增加或修改课程信息
    @PostMapping("/save")
    @ApiOperation(value="课程 -- 添加或修改",notes = "不带id为添加,否则为修改")
    public ResData<Boolean> saveCourse(@RequestBody CourseDTO courseDTO) {
        return courseService.saveCourse(courseDTO);
    }
    //假删除课程信息
    @DeleteMapping("/deleteByIds")
    @ApiOperation(value="课程 -- 批量删除(假)",notes = "传删除课程的id数组")
    public ResData<Boolean> falseDeleteCourseByIds(@RequestBody List<String> idList) {
        return courseService.falseDeleteCourseByIds(idList);
    }
    //查询教师课程所在的学年学期
    @GetMapping("/findTchCoYear")
    @ApiOperation(value="课程 -- 查询教师所有课程",notes = "(教师首页)")
    public ResData<ArrayList<TchCoYearVO>> findTchCoYear(String workId) {
        return courseService.findTchCoYear(workId);
    }

    @GetMapping("/findAllCourseSchoolYear")
    @ApiOperation(value="课程 -- 查询所有课程的学年数组")
    public ResData<LinkedHashSet<String>> findAllCourseSchoolYear() {
        return courseService.findAllCourseSchoolYear();
    }

    //查询教师课程所在的学年学期
    @GetMapping("/findTchCoYearList")
    @ApiOperation(value="课程 -- 查询教师课程所在学年学期年级")
    public ResData<TchCoYearListVO> findTchCoYearList(String workId) {
        return courseService.findTchCoYearList(workId);
    }

    //查询单个课程
    @GetMapping("/findOne")
    @ApiOperation(value="课程 -- 查询单个课程")
    public ResData<CourseOneVO> findOne(String courseId) {
        return courseService.findOne(courseId);
    }

    @GetMapping("/updateColor")
    @ApiOperation(value="课程 -- 修改课程颜色")
    public ResData<Boolean> updateColor(String color,String courseId) {
        return courseService.updateColor(color,courseId);
    }

    //查课程表
    @PostMapping("/courseTable")
    @ApiOperation(value="课程 -- 查课程表",notes = "workId和studentId二选一")
    public ResData<ArrayList<CourseTableVO>> findCourseTable(@RequestBody CourseTableDTO courseTableDTO) {
        return courseService.findCourseTable(courseTableDTO);
    }

    //表格导入
    // @ResponseBody
    @PostMapping("/fileImport")
    @ApiOperation("课程 -- 表格导入")
    public ResData<Boolean> courseImport(@RequestPart @ApiParam(value = "表格对象") MultipartFile file){
        return courseService.courseImport(file);
    }

    @GetMapping("/fileExport")
    @ApiOperation("课程 -- 表格导出")
    public void courseExport(HttpServletResponse response, FindAllCourseDTO findAllCourseDTO) {
        courseService.courseExport(response, findAllCourseDTO);
    }
}
